<?php
/*
	区域代理中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['pluginset']=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$_SESSION['forward_url']='jy_area_agent/index/';
	$return['setting']=$this->plugin_setting('page');
	set_html('title',$return['setting']['center']);
	$member=$this->get('member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$agent_area=$this->get('agent_area',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$level_id=$agent_area['level_id'];
	$member['leveltitle']=$this->getcolumn('level',array('id'=>$level_id),'title');
	$member['leveltitle']=$member['leveltitle']?:'默认等级';
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	$return['member']=$member;
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('mid'=>$_SESSION['uid']),'money');
	$data['balance_num']=$this->count('balance',array('mid'=>$_SESSION['uid']));
	//待结算佣金
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1);
	$data['order_num']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level <'=>18),'money');
	$data['commission_count']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'level <'=>18));
	if($agent_area['is_duodai']){
		$duodai=str_array($agent_area['duodai']);
		$data['area_num']=count($duodai);
	}else{
		$data['area_num']=$this->count('agent_area',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	$data['commission_xuni']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'xuni_money');
	$return['data']=$data;
	$return['item']=$agent_area;
	$pay=uni_setting('pay');
	$return['credit_rate']=$pay['credit'.$return['pluginset']['credit_type'].'_rate']?:1;
	$return['xuniname']=$this->xuniname;
	exi($return);
}
if($_RQ['op']=='change'){
	$post=get_postdata();
	$type=$return['pluginset']['credit_type'];
	$pay=uni_setting('pay');
	$credit_rate=$pay['credit'.$type.'_rate']?:1;
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
	if(!$post['jifen']){
		exi('请输入'.$this->xuniname.'额度！','error');
	}
	if($member['credit'.$type]<$post['jifen']){
		exi('转额度不能大于，当前剩余额度！','error');
	}
	$fee=$post['jifen']/$credit_rate;
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$type,$post['jifen'],false,'jy_area_agent','转换余额');
	model('core/member')->member_credit($_SESSION['uid'],'credit2',$fee,true,'jy_area_agent',$this->xuniname.'的转换');
	exi('转换成功！','','/index/');
}
?>